package edu.hawaii.duedates.library;

import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import org.junit.Before;
import org.junit.Test;
import edu.hawaii.duedates.BorrowedItem;

/**
 * JUnit test class for LenderComparator class.
 * @author John
 *
 */
public class TestLenderComparator {
  private BorrowedItem item;
  private BorrowedItem longItem;
  List<BorrowedItem> itemList = new ArrayList<BorrowedItem>();
  
  /**
   * Sets up the BorrowedItem object.
   */
  @Before
  public void setUp () {
    Calendar cal = Calendar.getInstance(Locale.US);
    cal.set(Calendar.MONTH, 0);
    cal.set(Calendar.DATE, 15);
    cal.set(Calendar.YEAR, 2009);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 0);
    item = new BorrowedItem("Cat in the Hat", cal, "Book", "UH Manoa");
    longItem = new BorrowedItem("Some insanely long title that no one would ever want to read",
        cal, "Video", "Hawaii State");
  }
  
  /**
   * TestComparator.
   */
  @Test
  public void testNormalOperation () {
    itemList.add(item);
    itemList.add(longItem);
    Collections.sort(itemList, new LenderComparator());
    assertEquals("Item 1", longItem, itemList.get(0));
    assertEquals("Item 2", item, itemList.get(1));
  }
}
